Skip to content

fix(presence): unmount timer-only zero-duration exits in the same flush - #1161

Open
dennev wants to merge 1 commit into
solidjs-community:mainfrom
dennev:fix/presence-zero-duration-exit
Open

dennev wants to merge 1 commit into
solidjs-community:mainfrom
dennev:fix/presence-zero-duration-exit

Conversation

@dennev

@dennev dennev commented Dec 2, 2026 •

Copy link
Copy Markdown

Fixes #1160.

Summary

  • Snapshot exitDuration when a timer-only exit starts (!options.animations) inside the existing transition memo in packages/presence/src/index.ts, adding no extra memo slots.
  • Derive isMounted() and isExiting() as false in the same reactive flush when that sampled timer-only exit duration is <= 0, instead of scheduling setTimeout(finishExit, exitDuration()).
  • For immediate exits, fire onExited from the exit effect without writing reactive state (avoiding EFFECT_WRITES_OWN_SOURCE and EFFECT_RELAY_TEAR), preserve the onFlush unmount-before-remount gap on item swaps, and guard finishExit against duplicate completion from done().
  • Keep animations: true with transitionDuration: 0 observing getAnimations() when the element is observable.
  • Add regression tests in packages/presence/test/createPresence.test.ts, a renderHydrationRoundTrip() test in packages/presence/test/hydration.test.tsx, and a patch changeset for @solid-primitives/presence.

Happy to adjust if maintainers prefer keeping the 1-tick exit state or another approach discussed in #1160.

Verification

  • Before the fix: reproduced separately on published @solid-primitives/presence@1.1.0 (solid-js@2.0.4) and on main (b879b1f960ec, unmodified packages/presence/src/index.ts tested in Linux Docker node:24 with the two client test files failing 4 failed | 63 passed (67)).
  • After the fix (Linux node:22 v22.23.5, pnpm install --frozen-lockfile):
    • pnpm --filter @solid-primitives/presence build passed
    • pnpm --filter @solid-primitives/presence test -- --run passed (3 test files, 68 passed, including test/hydration.test.tsx renderHydrationRoundTrip(), all 4 reactivity diagnostic scenarios, and the observable-animation regression)
    • pnpm --filter @solid-primitives/presence test:ssr -- --run passed (3 passed)
    • pnpm run verify:manifests, pnpm run test:scripts (9 passed), pnpm run check:peer-major, pnpm lint (0 errors), pnpm format:check, and pnpm run jsr:sync-versions:check passed
  • Not run locally: full monorepo pnpm test across unrelated packages and jsr-ci.yml Deno commands (deno.jsonc untouched).

Summary by CodeRabbit

  • Bug Fixes
    • Zero-duration exits now unmount in the same reactive update, avoiding a brief delay.
    • Exit timing is sampled when an exit begins, and detected animations can complete even when the transition duration is zero.
    • Improved handling of item swaps and hydration with zero-duration transitions.

@changeset-bot

changeset-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 74c6fef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solid-primitives/presence Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Timer-only presence exits with nonpositive sampled durations now unmount in the same reactive flush. Exit completion uses a shared helper. Tests cover exit timing, item replacement, animation completion, and hydration.

Changes: Presence exit timing

Layer / File(s) Summary
Sample exit duration and complete exits
packages/presence/src/index.ts
The transition record captures the exit duration when an exit begins. Timer-only exits with nonpositive durations become unmounted immediately. Timer and animation completion use a shared helper that prevents duplicate completion and calls onExited.
Test exit timing and hydration
packages/presence/test/createPresence.test.ts, packages/presence/test/hydration.test.tsx, .changeset/presence-zero-duration-exit.md
Tests cover same-flush unmounting, item replacement, sampled accessor durations, animation completion, and hydration. The changeset declares a patch release.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: davedbase, atk

Merge Risk: Minimal · up to 74c6f

Timer-only presence exits with a zero or negative duration now unmount in the same reactive flush, which removes the brief overlap of outgoing and incoming panels. Animation-aware exits and item-swap ordering are preserved, and regression and hydration tests cover the change. No remaining merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the primary change: timer-only exits with a zero or nonpositive duration now unmount in the same reactive flush. The changeset, the index.ts change (nonpositive sampled duration treate…
Linked Issues check Passed #1160 requires that, in timer-only mode (no animations: true), an exit with sampled duration <= 0 unmounts in the same reactive flush. The diff to packages/presence/src/index.ts implements this. T…
Out of Scope Changes check Passed All changed files relate to #1160. index.ts changes implement the same-flush exit, the onExited notification, the finishExit guard, and the createPresence doc note on nonpositive timer-only ex…
Full details: Title check

Explanation

The title names the primary change: timer-only exits with a zero or nonpositive duration now unmount in the same reactive flush. The changeset, the index.ts change (nonpositive sampled duration treated as immediate unmount), and the tests all match this. The title uses the conventional fix(presence) form and is specific, so it passes.

Full details: Linked Issues check

Explanation

#1160 requires that, in timer-only mode (no animations: true), an exit with sampled duration <= 0 unmounts in the same reactive flush. The diff to packages/presence/src/index.ts implements this. The transition memo samples exitDuration() at source change when options.animations is falsy. isMounted returns false when source() is false and the sampled duration is &lt;= 0, so no setTimeout is scheduled. The exit effect calls onExited directly and writes no signal, which avoids the EFFECT_WRITES_OWN_SOURCE and EFFECT_RELAY_TEAR diagnostics. For animations: true, the path still calls settleAnimations on observable elements with the sampled or current duration, so the getAnimations() wait is kept. finishExit guards duplicate completion per generation, and done() routes through it, so the timer and done() cannot both complete one exit. Regression tests and a hydration round-trip test are reported in the PR description. I did not run them. The test files were not inspected in this review, so the test coverage verdict rests on the PR description and the source diff.

Full details: Out of Scope Changes check

Explanation

All changed files relate to #1160. index.ts changes implement the same-flush exit, the onExited notification, the finishExit guard, and the createPresence doc note on nonpositive timer-only exits. The shortened onExited doc comment and the generation to transition rename describe the same mechanism. The test files cover the zero-duration, item-swap, diagnostics, and observable-animation cases that the issue names. The hydration test covers the same zero-duration path. The changeset is a patch for @solid-primitives/presence. No unrelated behavior change appears in the diff. The test file contents were not read in this review.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 706c0627-fa8b-49fb-b40c-3a7d95a7033f
Commits

Reviewing files that changed from the base of the PR and between b879b1f and 74c6fef.

Files selected for processing: 4

  • .changeset/presence-zero-duration-exit.md
  • packages/presence/src/index.ts
  • packages/presence/test/createPresence.test.ts
  • packages/presence/test/hydration.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[presence] createPresence with transitionDuration: 0 defers exit unmount via setTimeout(0)

1 participant